package com.jvup.gameshow.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.jvup.common.inject.EventControllerInjector;
import com.jvup.gameshow.R;
import com.jvup.common.support.base.BaseActivity;
import com.jvup.common.inject.ViewModelInjector;
import com.jvup.common.constant.Navigation;
import com.jvup.gameshow.controller.MainController;
import com.jvup.gameshow.databinding.ActivityMainBinding;
import com.jvup.gameshow.model.viewModel.impl.MainViewModel;
import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.antsrouter.inject.Autowired;

/**
 * 主入口页，进场页面。
 */
@RouteMapping(path = Navigation.Page.MainPage)
public class MainActivity extends BaseActivity<ActivityMainBinding> {

    @Autowired(injector = ViewModelInjector.class)
    private MainViewModel viewModel;

    @Autowired(injector = EventControllerInjector.class)
    MainController controller;

    private volatile boolean isClose = true;

    @Override
    public int layoutRid() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewModel.addCloseStateObserver(this::closePage);
        viewModel.onAddition(this, controller);
        controller.onAddition(viewModel);
    }

    public void closePage(boolean state) {
        if(state && isClose) {
            isClose = false;
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.HomePage).navigation();
            finish();
        }
    }

}
